package com.stock.demo.function.share.view;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.stock.demo.R;
import com.stock.demo.framework.ui.view.StockBaseDialog;
import com.stock.demo.model.MarketDetailBean;

/**
 * Created by xuzhaoyu on 17-8-1.
 */

public class TradeDialog extends StockBaseDialog {

    private MarketDetailBean mBean;
    private View mView;

    public TradeDialog(Context context, MarketDetailBean bean) {
        super(context);
        mBean = bean;
    }

    public TradeDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    @Override
    public void initWindow(WindowManager windowManager, Window window) {
        window.setGravity(Gravity.CENTER);
        int width = windowManager.getDefaultDisplay().getWidth();
        WindowManager.LayoutParams attributes = window.getAttributes();
        attributes.width = (int) (width * 0.8);
        attributes.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(attributes);
    }

    @Override
    public boolean setDialogCancelable() {
        return true;
    }

    @Override
    public View setDialogView() {
        mView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_trade, null);
        mView.findViewById(R.id.ll_trade_dialog_buy).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                StockPositionActivity.startAction(getContext(), 0, mBean);
                TradeDialog.this.dismiss();
            }
        });
        mView.findViewById(R.id.ll_trade_dialog_sell).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                StockPositionActivity.startAction(getContext(), 1, mBean);
                TradeDialog.this.dismiss();
            }
        });
        mView.findViewById(R.id.ll_trade_dialog_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                StockPositionActivity.startAction(getContext(), 2, mBean);
                TradeDialog.this.dismiss();
            }
        });
        return mView;
    }
}
